Repository navigation
feat(driver-sql, driver-turso): schema sync indexes (created_at, id) and owner_id without a declaration - #34044
Conversation
…and owner_id without a declaration The implicit index set now carries two system-column keys after the reference indexes: (created_at, id), the default list order, on every table that has both columns, and (owner_id) on an object whose fields carry it. The boot sync builds them, the drift differ expects them, and Turso's remote face composes the same set. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
…s on both dialects and both Turso faces Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
…o their own files Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
…r index in the index-set pins Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
📓 Docs Drift Check7 anchor(s) derived from 2 changed package(s); no hand-written page names any of them. What this run could not see
Coarse fallback — 18 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 47803a9f12820d082ef0b2e52d2bc2eea42c050a && git checkout 47803a9f12820d082ef0b2e52d2bc2eea42c050a
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin b4eea885058321e56776ab2b690e4f35e29b7a0c c42e6266edabe140b99083e9d4b7e2e9a54fe897 && git checkout -B drift-repro b4eea885058321e56776ab2b690e4f35e29b7a0c && git merge --no-ff c42e6266edabe140b99083e9d4b7e2e9a54fe897
node scripts/docs-audit/affected-docs.mjs --json b4eea885058321e56776ab2b690e4f35e29b7a0c |
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh Request: review · PR #34044 · area S2 (A4) · Fixes #33695 · head
|
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Review claim · head 6148308 · 2026-11-15T17:54Z review (review-b, areas S2+S4): ordinary ACCEPT read per review-checklist.md; the verdict follows on this PR. |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Review — PASSHead-sha:
The patch-id is |
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh
|
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh 席位核对Head-sha:
|
…ivation-ledger index lists (objectstack-ai#34205) <!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbKnsd8ZLsq9hBbRRm5JvJb2)_ Part of objectstack-ai#34126 Clause-②: no Metadata-protocol: none Skills-docs: none ## 维护者速读 - **改了什么**:只改测试。`sql-driver-widened-declared-unique.test.ts` 的 MySQL 8 和 MariaDB 两个 live 单元,在断言激活账本的索引名列表时,补上 `idx_sys_metadata_activation_created_at_id`。 - **为什么改**:PR objectstack-ai#34044(objectstack-ai#33695)让每张受管表都带上隐式的 `(created_at, id)` 索引,表上实际多了这一个索引。这两个单元只在 `Temporal Conformance (live PG + MySQL)` 里跑,而该 job 只在 push 和定时全量里跑,PR CI 和合并队列都不跑,所以 objectstack-ai#34044 没测到。00:10Z 的 4 小时全量(run 43778747333)因此变红。 - **风险与回滚**:断言仍是精确相等,只多了一个确定存在的名字,没有放宽,也没有跳过。回滚即 revert 本 PR。 - **先看**:测试文件里新加的 `DEFAULT_ORDER` 常量,以及两处 `toEqual`。 - **两分钟验证**:等下一次 4 小时全量(或 main 上的 push 运行),看 `Temporal Conformance (live PG + MySQL)` 是否转绿。 - **需要你做的**:无。区内自审(≤50 行、仅测试、`Clause-②: no`)。 ## What changes The live MySQL 8 cell, `an upgraded MySQL 8 database: the old key retires safely beside the functional guard`, lists every index on `sys_metadata_activation` after the safe replace and compares the list exactly. The 4-hourly full run on main at 00:10Z (run 43778747333, job 133010997457) failed there: ``` - Expected + Received [ "PRIMARY", + "idx_sys_metadata_activation_created_at_id", "uniq_sys_metadata_activation_metadata_type_package_id_name", "uniq_sys_metadata_activation_packageless", ] ``` The extra name is the `(created_at, id)` index that `IMPLICIT_SYSTEM_COLUMN_KEYS` gives every managed table since PR objectstack-ai#34044. It is not a timing budget. The MariaDB cell reads the same list through the same sync, so it gets the same name. It skips on the MySQL 8 server CI provisions, which is why only one case went red. Both lists now name `DEFAULT_ORDER`. The assertion stays exact: nothing is loosened, filtered or skipped. ## Tests - Local: `vitest run src/sql-driver-widened-declared-unique.test.ts`: 31 passed, 2 skipped (the two live MySQL cells, because no MySQL server is available here). ESLint `--no-inline-config` on the file exits 0, and `check-nul-bytes` exits 0. - The live cells run only in `Temporal Conformance (live PG + MySQL)`, which does not run on `pull_request` or `merge_group`. The proof is the full-run diff above, and the next push run on main or the next 4-hourly run will confirm it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh --> Co-authored-by: Claude <noreply@anthropic.com>
Requested by Steedos · project thread
Fixes #33695
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
(created_at, id)索引,也就是默认列表的排序。对象有owner_id时,再建一个(owner_id)索引,供私有 OWD 读取过滤用。Turso 远程库会建同一套隐式索引,其中也包括 driver-sql: master_detail and lookup columns get no index, so every controlled_by_parent read and every by-parent filter scans the detail table (114 ms → 1.1 ms with one index at 1M rows) #31882 引用列的索引。packages/drivers/driver-sql/src/schema-drift.ts,关注IMPLICIT_SYSTEM_COLUMN_KEYS和implicitReferenceIndexesOver中新增的循环。然后看sql-driver-rotation.ts中启动同步的入口判断,以及driver-turso/src/remote-transport.ts的buildDeclaredIndexDDL。OS_TEST_POSTGRES_URL=… pnpm --filter @objectstack/driver-sql exec vitest run src/sql-driver-33695-system-column-indexes.test.ts,预期 SQLite 和 live PG 两个 cell 全绿,PG 的执行计划里能看到idx_os33695_deal_created_at_id。What changes
The schema sync's implicit index set (
schema-drift.ts, seeded by #31882) gains two system-column keys after the reference indexes. This follows the maintainer ruling 「两个都加」 quoted on #33695.(created_at, id), namedidx_TABLE_created_at_id, on every table that physically has both builtin columns.(owner_id), namedidx_TABLE_owner_id, on an object whose fields carry a stored, single-valuedowner_id. An object with noowner_idgets no such index.Both are non-unique and take no organization key part. A declared index whose key already STARTS WITH the whole system key serves instead: a declared
(created_at)alone does not. A declaration of the same key converges on the same name.Three seams carry the set:
sql-driver-rotation.ts(approved surface extension): the boot sync openedsyncTableIndexesonly for objects with a unique field, an implicit reference, or declared indexes. An object with none of these would never have been given(created_at, id), while the differ expected it on every boot. The sync now opens on the implicit set itself.sql-driver-managed-drift.ts(approved surface extension, one argument):syncTableIndexespassesphysicalColumnstoimplicitReferenceIndexes. An adopted table without acreated_atcolumn is not asked to build an index it cannot have. Without this, every boot would write a false "index NOT created" line at durability levelerror.driver-turso/src/remote-transport.ts: the remote face'sbuildDeclaredIndexDDLcomposed only field-level unique and declared indexes. It never composed the driver-sql: master_detail and lookup columns get no index, so every controlled_by_parent read and every by-parent filter scans the detail table (114 ms → 1.1 ms with one index at 1M rows) #31882 reference indexes, while the drift differ (shared, run on both faces) expected them. It now appendsimplicitReferenceIndexes(...)against the columns it materialized.@objectstack/driver-sqlexportsimplicitReferenceIndexesfor this.SQLite and #33696. This PR adds the SQLite index too, so landing waits for PR #33897 (#33696), or the two land together. That follows the card's "SQLite: land with or after the R4 card". On PostgreSQL this PR pays off alone. I did not gate SQLite by dialect. A dialect-gated set would split the one composition that the sync, the differ and both Turso faces share, and nothing measured a harm from the SQLite index: at 1M rows the chained page is unchanged (1.97 s → 1.73 s, same plan).
Tests
packages/drivers/driver-sql/src/sql-driver-33695-system-column-indexes.test.ts(13 tests; the live PG cells ran) pins:owner_id, the cover-by-prefix rule, name convergence, multi-valued and formulaowner_idskipped, and no index or unbuildable report on a table with nocreated_at;safecreate_index, then built, then a silent third sync; an adopted table withoutcreated_atwith no index, no error line and no drift;idx_os33695_deal_created_at_idand the owner read readsidx_os33695_deal_owner_id;packages/drivers/driver-turso/src/turso-33695-implicit-index-parity.test.tspins that the local and remote faces land the same names and key parts, with none oncreated_by, and that the remote plan after a remote sync proposes no index.sql-driver-31882-*(owner_idis now indexed),sql-driver-schema,sql-driver-20432-*,sql-driver-11321-*,turso-local-remote-declared-index-parity,turso-remote-deferred-ddl,turso-remote-drift-apply-limitandturso-remote-migration-entries.Suites on the final head (merge of origin/main), and the ablations
Under
os-verify-lock, at head5594216903(after merging origin/main, then adriver-turso...closure build):Each ablation went through
scripts/ablation-replace.mjs(anchor 1 → 0, blob moved, restored from HEAD) and turned the pin red:physicalColumnsdropped fromsyncTableIndexes. Red: "an adopted table with no created_at column" (expected "vi.fn()" to not be called at all, but actually been called 1 times, the durability error line).owner_idpresence check dropped. 5 red, including "skips a multi-valued or formula owner_id" and "a table without a created_at column … reports nothing unbuildable".os33695_deal: expected { …(1) } to deeply equal { …(4) }; remote planexpected [ …(4) ] to deeply equal []).Acceptance notes
organization_id = ?. PostgreSQL then reads(created_at, id)backward and filters by organization, which is fine while one tenant dominates a table. With many tenants,(organization_id, created_at, id)would serve better. The ruling names(created_at, id), so this PR builds exactly that.(created_at, id)for the member's account page instead. Theowner_idindex pays off as owners multiply, and the card's own reading says so too ("grows with private-object size").implicitReferenceIndexeskeeps its name although it now returns the system-column keys too. Renaming it would have touched more ofsql-driver-managed-drift.tsthan the one approved argument.Verification
M0 bench (`packages/qa/dogfood/bench/sql-perf`), 1M line items, before (`63e47fee`) vs after (this branch), same box
bench.mjs --scale 1000000 --only scoped_list_unfiltered,scoped_account_list,list_filter_sort. The box is shared, so read the milliseconds as indicative and the plans as exact.PostgreSQL 16 (private cluster, 1M
bench_line_item):EXPLAIN ANALYZEof the admin page as the engine emits it (chained):Index Scan Backward using idx_bench_line_item_created_at_id, 0.253 ms.Unchained: 119.3 → 0.025 ms. The remaining HTTP time is the page's
count(*), which no index here serves.SQLite (better-sqlite3, 1M):
EXPLAIN QUERY PLAN:USE TEMP B-TREE FOR ORDER BY), 1968 → 1725 ms;SCAN bench_line_item | USE TEMP B-TREE FOR ORDER BY1578 ms →SCAN bench_line_item USING INDEX idx_bench_line_item_created_at_id0.16 ms.After schema sync, both dialects list
idx_TABLE_created_at_idon every bench table andsys_record_share.idx_TABLE_owner_idappears on every bench object, all of which carryowner_id.Gates
Derived with
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack, 71 families. The--ranreconciliation: 66 were run locally and each exited 0.check:query-options-erasurehit a 300 s wrapper timeout once and exited 0 on its rerun.The PR-body gates exited 0 on this body:
check-changeset-no-majorcheck-closing-keyword-paritycheck-adr-0087-registrationcheck-partof-closing-keywordNOT MEASURED locally, left to CI's
Lint & Repo Gatesand type-check lanes:check:dts-closure,check:published-files,check:sourcemap-no-sources-content,check:dual-build-cjs-loadsandcheck:type-check-debt. The reason: each needs a declaration build under the shared verify lock, and two 9-minute acquisitions timed out behind another seat's bundle. The typecheck of both touched packages did run against a full declaration build, as shown above.Dependents, the test files that read indexes or drift through a driver, after a closure build at the final head, all exit 0:
src/migrations/: 359 tests.pnpm lintis CI's.eslint --no-inline-configon the touched files exited 0.Generated by Claude Code
🤖 Generated with Claude Code